package com.ews.onlineexchange.controller;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;

import com.ews.onlineexchange.model.AgentService;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class AgentServiceList extends EntityQuery<AgentService> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private AgentService agentService = new AgentService();

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<AgentService> entity) {
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		restrictions.add(cb.equal(entity.get("delFlag"), DataEntity.DEL_FLAG_NORMAL));
		if (!StringUtils.isBlank(getAgentService().getName()))
			restrictions.add(cb.like(entity.get("name"), "%".concat(getAgentService().getName()).concat("%")));
		return restrictions;
	}

	public AgentServiceList() {
		setMaxResults(null);
	}

	public AgentService getAgentService() {
		return agentService;
	}

}
